package com.atguigu.lease.app.controller;

import com.atguigu.lease.app.interceptor.WebAppAuthInterceptor;
import com.atguigu.lease.app.service.ViewAppointmentService;
import com.atguigu.lease.model.bean.ViewAppointment;
import com.atguigu.lease.model.result.Response;
import com.atguigu.lease.model.vo.app.AppointmentItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="预约模块")
@RestController
@RequestMapping("/app/appointment")
public class AppointmentController {

    @Autowired
    private ViewAppointmentService viewAppointmentService;
    @Operation(summary = "2、查询用户的预约看房列表")
    @GetMapping("listItem")
    public Response<List<AppointmentItemVo>> listItem(){
        return Response.ok(viewAppointmentService
                .getAppointmentItemVoList(WebAppAuthInterceptor.getUserId()));
    }
    @Operation(summary = "1、新增或更新预约看房信息")
    @PostMapping("/saveOrUpdate")
    public Response saveOrUpdate(@RequestBody ViewAppointment viewAppointment) {
        //因为预约看房记录需要和用户id绑定，所以保存前需要先获取用户id设置
        Long userId = WebAppAuthInterceptor.getUserId();
        viewAppointment.setUserId(userId);
        viewAppointmentService.saveOrUpdate(viewAppointment);
        return Response.ok(null);
    }
}
